﻿using SQLite.Reps;
using SQLite.Reps.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SQLite
{
	public class EnWordsDbInitializer
	{
        private SQLiteAsyncConnection _enWordsConnection;

		public TestRep TestRepo { get; private set; }
        public WordRep WordsRepo { get; private set; }
        public CircleRep CirclesRepo { get; private set; }

		public EnWordsDbInitializer()
		{
            _enWordsConnection = new EnWordsSQLiteAsyncConnection();

			TestRepo = new TestRep(_enWordsConnection);
            CirclesRepo = new CircleRep(_enWordsConnection);
            WordsRepo = new WordRep(_enWordsConnection);
		}

        public async Task CreateTables()
        {
            var tables = GetAllReps().Select(x => x.TableType).ToArray();
            await _enWordsConnection.CreateTablesAsync(tables);
        }

		private IEnumerable<IRep> GetAllReps()
		{
			yield return TestRepo;
            yield return CirclesRepo;
            yield return WordsRepo;
		}
	}
}
